<!-- 后台管理 - 员工管理 -->
<template>
  <div id="box" style="">
    <!--顶部按钮-->
    <div style="height: 50px;line-height: 50px;">
      <el-row>
        <el-col align="right">
          <el-button @click="Add">添加</el-button>
          <el-button style="margin-left: 20px;" @click="Modify">修改</el-button>
          <el-button style="margin-left: 20px;" @click="Reset">重置密码</el-button>
          <el-button style="margin-left: 20px;" @click="getrole">分配角色</el-button>
        </el-col>
      </el-row>
      <el-dialog :visible.sync="staffInfoDialog" title="员工信息" align="left" width="40%">
        <div style="margin-top: -35px; padding-left: 15px; line-height: 30px;" v-html="staffInfo" />
      </el-dialog>
      <el-dialog :visible.sync="modal1" title="添加人员" align="center" width="40%">
        <el-form ref="Addition" :model="Addit" :rules="Addrule" label-width="110px">
          <div>
            <el-row>
              <el-col :span="20" :offset="1">
                <el-form-item label="用户名" prop="username"><el-input v-model="Addit.username" clearable
                    placeholder="" /></el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="密码" prop="password"><el-input v-model="Addit.password" placeholder=""
                    type="password" password /></el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="姓名" prop="nickname"><el-input v-model="Addit.nickname" clearable
                    placeholder="" /></el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="人员类别" prop="userType">
                  <el-select v-model="Addit.userType" :label-in-value="true" clearable placeholder="" filterable
                    style="text-align: left">
                    <el-option v-for="item in userType" :key="item.value" :value="item.value">{{ item.label
                      }}</el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="当前科室" prop="departmentName">
                  <el-select v-model="Addit.departmentName" :label-in-value="true" clearable placeholder="" filterable
                    style="text-align: left">
                    <el-option v-for="item in alldepts" :key="item.id" :value="item.name">{{ item.name }}</el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>

          </div>
        </el-form>
        <div slot="footer">
          <el-row>
            <el-col style="text-align: center;" class="button">
              <el-button @click="Addcancel()">取消</el-button>
              <el-button style="margin-left: 30px;" class="sousuobtn" @click="Addconfirm('')">确认</el-button>
            </el-col>
          </el-row>

        </div>
      </el-dialog>
      <el-dialog :visible.sync="modal2" title="修改人员信息" align="center" width="40%">
        <el-form ref="Mod" :model="Modit" :rules="Modrule" label-width="110px">
          <div>
            <el-row>
              <el-col :span="20" :offset="1">
                <el-form-item label="用户名" prop="username"><el-input v-model="Modit.username" clearable placeholder=""
                    disabled /></el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="姓名" prop="name"><el-input v-model="Modit.name" clearable
                    placeholder="" /></el-form-item>
              </el-col>
            </el-row>
            <!--                     <el-row> -->
            <!--                         <el-col :span="20" :offset="1" style="margin-top: -14px;"> -->
            <!--                             <el-form-item label="性别" prop="sex"> -->
            <!--                                 <el-select v-model="Modit.sex" :label-in-value="true" clearable placeholder="" -->
            <!--                                           style="text-align: left"> -->
            <!--                                     <el-option v-for="item in comSexList" :key="item.code" :value="item.code"> -->
            <!--                                         {{item.name}} -->
            <!--                                     </el-option> -->
            <!--                                 </el-select> -->
            <!--                             </el-form-item> -->
            <!--                         </el-col> -->
            <!--                     </el-row> -->
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="人员类别" prop="userType">
                  <el-select v-model="Modit.userType" :label-in-value="true" clearable placeholder="" filterable
                    style="text-align: left">
                    <el-option v-for="item in userType" :key="item.value" :value="item.value">{{ item.label
                      }}</el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="当前科室" prop="departmentName">
                  <el-select v-model="Modit.departmentName" :label-in-value="true" clearable placeholder="" filterable
                    style="text-align: left">
                    <el-option v-for="item in alldepts" :key="item.id" :value="item.name">{{ item.name }}</el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!--                     <el-row> -->
            <!--                         <el-col :span="20" :offset="1" style="margin-top: -14px;"> -->
            <!--                             <el-form-item label="身份证号" prop="idcard"> -->
            <!--                                 <el-input v-model="Modit.idcard" clearable placeholder=""></el-input> -->
            <!--                             </el-form-item> -->
            <!--                         </el-col> -->
            <!--                     </el-row> -->
            <!--                     <el-row> -->
            <!--                         <el-col :span="20" :offset="1" style="margin-top: -14px;"> -->
            <!--                             <el-form-item label="证书编号" prop="certid"> -->
            <!--                                 <el-input v-model="Modit.certid" clearable placeholder=""></el-input> -->
            <!--                             </el-form-item> -->
            <!--                         </el-col> -->
            <!--                     </el-row> -->
            <el-row>
              <el-col :span="20" :offset="1" style="margin-top: -14px;">
                <el-form-item label="状态" prop="enabled">
                  <el-select v-model="Modit.enabled" :label-in-value="true" clearable placeholder=""
                    style="text-align: left">
                    <el-option value="true" label="正常">正常</el-option>
                    <el-option value="false" label="禁用">禁用</el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
        <div slot="footer">
          <el-row>
            <el-col style="text-align: center;" class="button">
              <el-button @click="Modcancel()">取消</el-button>
              <el-button style="margin-left: 30px;" class="sousuobtn" @click="Modconfirm('')">确认</el-button>
            </el-col>
          </el-row>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="modal3" title="重置密码" align="center" width="40%">
        <el-form label-width="110px">
          <div>
            <el-row>
              <el-col :span="20" :offset="1">
                <el-form-item label="密码" prop="updatepassword"><el-input v-model="updatepassword" placeholder="请输入修改密码"
                    type="password" password /></el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
        <div slot="footer">
          <el-row>
            <el-col style="text-align: center;" class="button">
              <el-button @click="Resetcancel()">取消</el-button>
              <el-button style="margin-left: 30px;" class="sousuobtn" @click="Resetconfirm('')">确认</el-button>
            </el-col>
          </el-row>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="dialoggetrole" title="分配角色" align="center" width="40%">
        <span v-for="item in rolesDivision" :key="item.id" style="text-align:left">
          <div v-if="!!item[0].hospitalname" style="float: left;font-size:18px; padding:15px 10px ;width: 100%;"><b>{{
            item[0].hospitalname }}</b></div>
          <el-checkbox-group v-model="checkedroles">
            <el-checkbox v-for="per in item" :key="per.id" style="width: auto;margin-bottom: 10px;margin-left: 5px;"
              :label="per.id" border>
              {{ per.name }}
            </el-checkbox>
          </el-checkbox-group>
        </span>
        <div slot="footer">
          <el-row>
            <el-col style="text-align: center;" class="button">
              <el-button @click="cancelrole()">取消</el-button>
              <el-button style="margin-left: 30px;" class="sousuobtn" @click="saverole('')">确认</el-button>
            </el-col>
          </el-row>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="dialoggetdept" title="分配科室" align="center" width="40%">
        <el-checkbox-group v-model="checkeddepts">
          <el-checkbox v-for="item in alldepts" :key="item.id" style="width: 25%;margin-bottom: 10px;margin-left: 5px;"
            :label="item.id" border>{{ item.name }}</el-checkbox>
        </el-checkbox-group>
        <div slot="footer">
          <el-row>
            <el-col style="text-align: center;" class="button">
              <el-button @click="canceldept()">取消</el-button>
              <el-button style="margin-left: 30px;" class="sousuobtn" @click="savedept('')">确认</el-button>
            </el-col>
          </el-row>
        </div>
      </el-dialog>
    </div>
    <!--左侧树-->
    <div style="float: left; width: 270px;padding: 20px 0px;background-color: white;height: 680px;overflow:auto">
      <el-tree ref="tree" :highlight-current="true"
        style="padding: 10px 10px;margin-top: 20px;border-top: 1px solid #E0E0E0;width: 100%;font-size:14px"
        :data="basedata" :props="defaultProps" default-expand-all @node-click="handleNodeClick">
        <span slot-scope="{ node, data }" class="custom-tree-node">
          <span>
            <i class="fa fa-file-text-o" style="color: orange;" />
            <span style="margin-left: 5px;">{{ node.label }}</span>
          </span>
        </span>
      </el-tree>
    </div>
    <!--右侧表格-->
    <div style="float: right; width: calc(100% - 280px);padding: 20px;background-color: white;">
      <el-form label-width="80px">
        <el-row>
          <el-col :span="5">
            <el-form-item label="医院编码:" prop="hospitalId"><el-input v-model="hospitalId" clearable placeholder=""
                disabled /></el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="医院名称:" prop="hospitalName"><el-input v-model="hospitalName" clearable placeholder=""
                disabled /></el-form-item>
          </el-col>
          <!--                <el-col :span="5">-->
          <!--                    <el-form-item label="医院级别:" prop="hosgrade">-->
          <!--                        <el-select v-model="hosgrade" :label-in-value="true" clearable placeholder=""-->
          <!--                                  style="text-align: left">-->
          <!--                            <el-option v-for="item in levelList" :key="item.id" :value="item.id">{{ item.name }}-->
          <!--                            </el-option>-->
          <!--                        </el-select>-->
          <!--                    </el-form-item>-->
          <!--                </el-col>-->
          <!--                <el-col :span="5">-->
          <!--                    <el-form-item label="医院状态:" prop="hospitalstate">-->
          <!--                        <el-select v-model="hospitalstate" clearable placeholder="" style="text-align: left">-->
          <!--                            <el-option value="true">正常</el-option>-->
          <!--                            <el-option value="false">禁用</el-option>-->
          <!--                        </el-select>-->
          <!--                    </el-form-item>-->
          <!--                </el-col>-->
          <!--                <el-col :span="4">-->
          <!--                    <el-form-item label="行政区码:" prop="areaCodeCounty">-->
          <!--                        <el-input v-model="areaCodeCounty" clearable placeholder=""></el-input>-->
          <!--                    </el-form-item>-->
          <!--                </el-col>-->
          <!--            </el-row>-->
          <!--            <el-row>-->
          <!--                <el-col :span="5" style="margin-top: -14px">-->
          <!--                    <el-form-item label="用户名:" prop="searchusername">-->
          <!--                        <el-input v-model="searchusername" clearable placeholder=""></el-input>-->
          <!--                    </el-form-item>-->
          <!--                </el-col>-->
          <!--                <el-col :span="5" style="margin-top: -14px">-->
          <!--                    <el-form-item label="姓名:" prop="searchnickname">-->
          <!--                        <el-input v-model="searchnickname" clearable placeholder=""></el-input>-->
          <!--                    </el-form-item>-->
          <!--                </el-col>-->
          <!--                <el-col :span="5" style="margin-top: -14px">-->
          <!--                    <el-form-item label="状态:" prop="searchstate">-->
          <!--                        <el-select v-model="searchstate" :label-in-value="true" clearable placeholder=""-->
          <!--                                  style="text-align: left">-->
          <!--                            <el-option value="true">正常</el-option>-->
          <!--                            <el-option value="false">禁用</el-option>-->
          <!--                        </el-select>-->
          <!--                    </el-form-item>-->
          <!--                </el-col>-->
          <!--                <el-col :span="1" style="margin-left: 10px;margin-top: -13px">-->
          <!--                    <el-button class="sousuobtn" style="font-size: 14px;" @click="selectChange">-->
          <!--                        查询-->
          <!--                    </el-button>-->
          <!--                </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-table border height="575" highlight-current-row :columns="columnsCharge1" :data="data1" size="small"
              overflow:auto @row-click="clickPerson">
              <el-table-column label="用户名" prop="email" align="center" />
              <el-table-column label="姓名" prop="name" align="center" />
              <el-table-column label="所属机构" prop="hospitalId" align="center" />
              <el-table-column label="状态" prop="enabled" align="center">
                <template slot-scope="scope">
                  <span>
                    {{ scope.row.enabled ? '正常' : '禁用' }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <span>
                    <el-button size="mini" type="primary" @click="showmessage(scope.row)">查看详细信息</el-button>
                  </span>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import { findUserDept, findUserDept2, queryTreeList, queryUser1, queryHospitalId, postRegister1, postUpdateAppUserG, postResetPassword2, findRolesByUser1, setRoleToUser2, setDeptToUser } from '@/api/back-management/BG_employee'

export default {
  data() {
    return {
      // 树形结构数据，存在children中，暂无父级数据
      basedata: [],
      // 树子节点
      defaultProps: {
        children: 'children',
        // 显示的数据
        label: 'hospitalName'
      },
      hospitalId: '',
      hospitalName: '',
      hosgrade: '',
      hospitalstate: '',
      areaCodeCounty: '',
      searchusername: '',
      searchnickname: '',
      searchstate: '',
      // 医院等级
      levelList: [],
      // 科室信息表
      columnsCharge1: [
        {
          title: '用户名',
          key: 'email',
          // width: 218,
          resizable: true,
          align: 'center'
        },
        {
          title: '姓名',
          key: 'name',
          // width: 218,
          resizable: true,
          align: 'center'
        },
        {
          title: '所属机构',
          key: 'hospitalId',
          // width: 218,
          resizable: true,
          align: 'center'
        },
        {
          title: '状态',
          key: 'enabled',
          // width: 219,
          resizable: true,
          align: 'center',
          render: (h, params) => {
            const enabled = params.row.enabled
            if (enabled === true) {
              return h('span', '正常')
            }

            if (enabled === false) {
              return h('span', '禁用')
            }
          }
        },
        {
          title: '操作',
          key: 'action',
          width: 150,
          align: 'center',
          render: (h, params) => {
            return h(
              'Button',
              {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.showmessage(params.index)
                  }
                }
              },
              '查看详细信息'
            )
          }
        }
      ],
      data1: [],
      // 表单分页总数
      pageTotal: 0,
      // 从第一页开始
      pageNum: 1,
      // 每页显示多少条
      pageSize: 10,
      userType: [{ value: '医生', label: '医生' }, { value: '护士', label: '护士' }, { value: '主任', label: '主任' }],
      // 人员类型
      roletype: [],
      // 当前科室
      alldepts: [],
      // 添加人员信息弹窗
      modal1: false,
      // 新增人员表单
      Addit: {
        username: '',
        password: '',
        nickname: '',
        sex: '',
        persontype: '',
        deptId: '',
        idcard: '',
        certid: '',
        userType: '',
        departmentName: ''
      },
      // 新增所需信息
      AdditList: {
        hospitalId: '',
        username: '',
        password: '',
        nickname: '',
        sex: '',
        persontype: '',
        deptId: '',
        idcard: '',
        certid: '',
        userType: '',
        departmentName: ''
      },
      // 新增人员表单不能为空
      Addrule: {
        username: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        password: [
          {
            required: false,
            message: ' ',
            trigger: 'blur'
          }
        ],
        nickname: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        sex: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        persontype: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        deptId: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        idcard: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ]
      },
      // 修改人员信息弹窗
      modal2: false,
      // 修改人员信息表单
      Modit: {
        username: '',
        nickname: '',
        sex: '',
        persontype: '',
        deptId: '',
        idcard: '',
        certid: '',
        enabled: '',
        departmentName: '',
        userType: ''
      },
      // 修改人员信息表单不能为空
      Modrule: {
        username: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        nickname: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        sex: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        persontype: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        deptId: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ],
        idcard: [
          {
            required: true,
            message: ' ',
            trigger: 'blur'
          }
        ]
      },
      // 重置密码弹窗
      modal3: false,
      // 重置密码的密码
      updatepassword: '',
      id: '',
      // 性别
      comSexList: [],
      // 分配角色弹窗
      dialoggetrole: false,
      // 角色
      allroles: [],
      // 权限
      checkedroles: [],
      // 分配科室弹窗
      dialoggetdept: false,
      // 科室
      checkeddepts: [],
      staffInfoDialog: false, // 员工信息弹窗
      staffInfo: '', // 员工信息-弹窗信息
      rolesDivision: '' // 分配角色数据源
    }
  },
  created() {
    // 得到树
    this.getbasedata()
    // 医院级别
    // this.levelDropdown();
    // 科室类型
    // this.getalltypes();
    // 人员类型
    // this.gettype();
    // 当前科室
    // this.getalldepts();
  },
  methods: {
    showmessage(row) {
      let data = {}
      let showdept = ''
      let showrole = ''
      const that = this
      const id = row.id
      const b = {
        id: id,
        token: this.$store.getters.token
      }

      findUserDept(b).then(res => {
        const deptname = []
        if (!!res && res.length !== 0) {
          // data = res.replace('[', '').replace(']', '').replace(/\ /g, '').split(',')
          data = res
          for (let i = 0; i < data.length; i++) {
            for (let x = 0; x < that.alldepts.length; x++) {
              if (data[i].toString() === that.alldepts[x].id) {
                deptname.push(that.alldepts[x].name)
              }
            }
          }
          for (let y = 0; y < deptname.length; y++) {
            showdept = showdept + '  ' + deptname[y]
          }
        }
        findUserDept2(b).then(res => {
          for (let x = 0; x < res.length; x++) {
            showrole = showrole + '  ' + res[x].name
          }
          this.staffInfoDialog = true
          //     this.staffInfo = `<br>姓名：${row.name}
          // <br>职称：${row.userType}
          // <br>所属部门：${row.departmentName}
          // <br>部门权限：${showdept}
          // <br>拥有角色：${showrole}
          // <br>电话/email：${row.email}`
          this.staffInfo = `<div>姓名：${row.name}</div>
<div>职称：${row.userType}</div>
<div>所属部门：${row.departmentName}</div>
<div>部门权限：${showdept}</div>
<div>拥有角色：${showrole}</div>
<div>电话/email：${row.email}</div>`

          //     that.$Modal.info({
          //       title: '员工信息：',
          //       content: `<br>姓名：${row.name}
          // <br>职称：${row.userType}
          // <br>所属部门：${row.departmentName}
          // <br>部门权限：${showdept}
          // <br>拥有角色：${showrole}
          // <br>电话/email：${row.email}`
          //     })
        })
      })
    },
    // 得到树数据方法
    getbasedata() {
      this.getbase = {
        id: '0',
        type: '',
        name: ''
      }
      const data = {
        token: this.$store.getters.token,
        start: this.curPage - 1,
        length: this.pageSize,
        parentId: 'root'
      }
      queryTreeList(data).then(res => {
        // res = JSON.parse(res)
        this.basedata = res
      })
    },
    // 单击左侧树获得数据方法
    handleNodeClick(data) {
      this.hospitalId = data.hospitalId
      this.hospitalName = data.hospitalName
      this.hosgrade = data.hosgrade
      this.hospitalstate = data.enabled + ''
      this.areaCodeCounty = data.areaCodeCounty
      this.selectChange(this.hospitalId)
      // 得到权限
      this.getallroles(this.hospitalId)
      this.getalldepts()
    },
    // // 医院级别
    // levelDropdown() {
    //     var a = "HOSGRADE";
    //     $.ajax({
    //         method: "GET",
    //         url: '/api-his/his/commons/dictionary',
    //         params: {
    //             parent_type: a
    //         },
    //         headers: {
    //             'Content-Type': 'application/x-www-form-urlencoded',
    //             "Authorization": "Bearer " + localStorage.getItem("access_token")
    //         },
    //         withCredentials: true
    //     }).then((response) => {
    //         this.levelList = response.data;
    //     })
    // },
    // // 科室类型
    // getalltypes() {
    //     let that = this;
    //     $.ajax({
    //         method: "get",
    //         headers: {
    //             'Content-Type': 'application/json; charset=utf-8',
    //             "Authorization": "Bearer " + localStorage.getItem("access_token")
    //         },
    //         url: '/api-his/his/commons/dictionary?parent_type=DETP_TYPE',
    //     }).then(function (res) {
    //         res = res.data
    //         that.choseoption = res
    //     });
    // },
    // 查询表格
    selectChange(data) {
      // const that = this
      var d = {
        start: 0,
        length: 99999999,
        id: data,
        hospitalId: data,
        token: this.$store.getters.token
      }
      queryUser1(d).then(response => {
        // res = JSON.parse(response)
        this.data1 = response.data
        // this.pageTotal = response.data.total;
      })
    },
    // 获取分页数值
    handlePage(value) {
      this.pageNum = value
      this.selectChange()
    },
    // 获取分页条数
    handlePageSize(value) {
      this.pageSize = value
      this.selectChange()
    },
    // // 人员类型
    // gettype() {
    //     let that = this;
    //     $.ajax({
    //         method: "get",
    //         headers: {
    //             'Content-Type': 'application/json; charset=utf-8',
    //             "Authorization": "Bearer " + localStorage.getItem("access_token")
    //         },
    //         url: '/api-his/his/commons/dictionary?parent_type=PERSON_TYPE',
    //     }).then(function (res) {
    //         res = res.data
    //         that.roletype = res
    //     });
    // },
    // 当前科室
    getalldepts() {
      const that = this
      var b = { token: this.$store.getters.token, hospitalId: that.hospitalId }

      queryHospitalId(b).then(res => {
        // res = JSON.parse(res)
        this.alldepts = res.data
      })
    },
    // 控制新增弹窗
    Add() {
      if (this.hospitalId === '' || this.hospitalId === undefined) {
        this.$message({
          message: '请选择医院',
          type: 'warning'
        })
      } else {
        this.modal1 = true
        if (this.$refs['Addition'] !== undefined) {
          this.$refs['Addition'].resetFields()
        }
        this.Addit.password = ''
        // this.sexDropdown();
      }
    },
    // 新增确认
    Addconfirm() {
      this.AdditList.hospitalId = this.hospitalId
      this.AdditList.username = this.Addit.username
      this.AdditList.password = this.Addit.password
      this.AdditList.nickname = this.Addit.nickname
      this.AdditList.sex = this.Addit.sex
      this.AdditList.persontype = this.Addit.persontype
      this.AdditList.deptId = this.Addit.deptId
      this.AdditList.idcard = this.Addit.idcard
      this.AdditList.certid = this.Addit.certid
      this.AdditList.token = this.$store.getters.token
      var data = {}
      var b = {
        username: this.AdditList.username,
        password: this.AdditList.password,
        deptId: '123',
        nickname: this.AdditList.nickname,
        hospitalId: this.AdditList.hospitalId,
        token: this.$store.getters.token,
        userType: this.Addit.userType,
        departmentName: this.Addit.departmentName
      }
      data.username = this.AdditList.username
      data.password = this.AdditList.password
      data.nickname = this.AdditList.nickname
      data.hospitalId = this.AdditList.hospitalId
      data.token = this.$store.getters.token
      // debugger
      console.log(b)
      this.$refs['Addition'].validate(valid => {
        if (valid) {
          postRegister1(b).then(res => {
            console.log('添加成功的信息', res)
            this.$message({
              message: '添加成功',
              type: 'success'
            })
            this.modal1 = false
            this.selectChange(this.hospitalId)
            if (this.$refs['Addition'] !== undefined) {
              this.$refs['Addition'].resetFields()
            }
            this.Addit.password = ''
          }).catch(error => {
            console.log(error)
            this.$message({
              message: '添加失败',
              type: 'error'
            })
          })
        } else {
          this.$message({
            message: '请将必填项填写完整',
            type: 'error'
          })
          return
        }
      })
    },
    // 新增取消
    Addcancel() {
      this.modal1 = false
    },
    // 单击表格内人员进行修改
    clickPerson(data) {
      this.Modit = data
      this.Modit.sex = data.sex + ''
      this.Modit.enabled = data.enabled + ''
      this.id = data.id
    },
    // 控制修改弹窗
    Modify() {
      if (this.Modit.hospitalId === '' || this.Modit.hospitalId === undefined) {
        this.$message({
          message: '请选择人员',
          type: 'warning'
        })
      } else {
        this.modal2 = true
        // this.sexDropdown();
      }
    },
    // 确认修改
    Modconfirm() {
      this.Modit.token = this.$store.getters.token
      // var data = {}
      this.$refs['Mod'].validate(valid => {
        if (valid) {
          postUpdateAppUserG(this.Modit).then(res => {
            this.$message({
              message: '修改成功！',
              type: 'success'
            })
            this.modal2 = false
            this.$refs['Mod'].resetFields()
            this.Modit.hospitalId = ''
            this.selectChange(this.hospitalId)
          }).catch(error => {
            console.log(error)
            this.$message({
              message: '修改失败',
              type: 'error'
            })
          })
        } else {
          this.$message({
            message: '请将必填项填写完整',
            type: 'error'
          })
          return
        }
      })
    },
    // 修改取消
    Modcancel() {
      this.modal2 = false
    },
    // 控制重置密码弹窗
    Reset() {
      if (this.Modit.hospitalId === '' || this.Modit.hospitalId === undefined) {
        this.$message({
          message: '请选择人员',
          type: 'warning'
        })
      } else {
        this.modal3 = true
      }
    },

    // 确认重置
    Resetconfirm() {
      var b = {
        id: this.id,
        password: this.updatepassword,
        token: this.$store.getters.token
      }
      postResetPassword2(b).then(response => {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.modal3 = false
        if (this.$refs['Mod'] !== undefined) {
          this.$refs['Mod'].resetFields()
        }
        this.Modit.hospitalId = ''
        this.selectChange(this.hospitalId)
      })
        .catch(error => {
          this.$message({
            message: error.response.data.message,
            type: 'error'
          })
        })
    },
    // 重置取消
    Resetcancel() {
      this.modal3 = false
    },
    // 得到所有角色信息
    getallroles(hospitalId) {
      const that = this
      var b = {
        token: this.$store.getters.token,
        hospitalId: hospitalId
      }
      findRolesByUser1(b).then(res => {
        // res = JSON.parse(res)
        // res = res.data

        const arr = []
        const arrDivisio = []

        for (const index in res) {
          console.log(index, Array.isArray(res[index]))
          console.log(res)
          if (Array.isArray(res[index])) {
            arrDivisio.push(res[index])
            arr.push(...res[index])
          }
        }
        that.allroles = arr
        that.rolesDivision = arrDivisio
      })
    },
    // 分配角色
    getrole() {
      if (this.id !== undefined && this.id !== '') {
        const that = this
        this.id = that.id
        var b = {
          id: that.id,
          token: this.$store.getters.token
        }
        findUserDept2(b).then(res => {
          that.checkedroles = []
          for (let i = 0; i < res.length; i++) {
            that.checkedroles.push(res[i].id)
          }
        })
        that.dialoggetrole = true
      } else {
        this.$message({
          message: '还未选择分配权限角色',
          type: 'warning'
        })
      }
    },
    // 对话框确认是触发方法
    saverole() {
      const that = this
      // const id = this.id
      let data = JSON.stringify(that.checkedroles)
      data = data
        .replace('[', '')
        .replace(']', '')
        .replace(/\"/g, '')
      var b = {
        id: this.id,
        idd: data,
        token: this.$store.getters.token
      }
      setRoleToUser2(b).then(res => {
        // if (res && JSON.parse(res) && JSON.parse(res).code === 9999) {
        if (res && res.code === 9999) {
          // const msg = JSON.parse(res).message
          const msg = res.message
          this.$message({
            message: msg,
            type: 'error'
          })
        } else {
          that.dialoggetrole = false
          that.checkedroles = []
          this.$message({
            message: '分配角色成功',
            type: 'success'
          })
        }
      })
    },
    // 取消分配
    cancelrole() {
      this.dialoggetrole = false
    },
    // 得到选中行角色拥有科室信息
    getdept() {
      if (this.id !== undefined && this.id !== '') {
        this.dialoggetdept = true
        // const that = this
        const id = this.id
        var b = {
          id: id,
          token: this.$store.getters.token
        }
        findUserDept(b).then(res => {
          const data = res
            .replace('[', '')
            .replace(']', '')
            .replace(/\ /g, '')
            .split(',')
          this.checkeddepts = []
          for (let i = 0; i < data.length; i++) {
            this.checkeddepts.push(data[i])
          }
          // for (let y = 0; y < this.alldepts.length; y++) {
          //     if (this.Modit.deptId == this.alldepts[y].deptId) {
          //         this.alldepts[y].disabled = true;
          //     } else {
          //         this.alldepts[y].disabled = false;
          //     })
          // }
        })
      } else {
        this.$message({
          message: '还未选择分配科室角色',
          type: 'warning'
        })
      }
    },
    // 对话框确认时触发方法
    savedept() {
      const that = this
      const id = this.id
      let data = JSON.stringify(that.checkeddepts)
      data = data
        .replace('[', '')
        .replace(']', '')
        .replace(/\"/g, '')
      var b = {
        id: id,
        idd: data,
        token: this.$store.getters.token
      }
      setDeptToUser(b).then(res => {
        res = res.data
        this.$message({
          message: '分配科室成功',
          type: 'success'
        })
        that.dialoggetdept = false
      })
    },
    // 取消科室分配
    canceldept() {
      this.dialoggetdept = false
    }
    // // 性别
    // sexDropdown(value) {
    //     var a = "SEXCODE";
    //     $.ajax({
    //         method: "GET",
    //         url: '/api-his/his/commons/dictionary',
    //         params: {
    //             parent_type: a
    //         },
    //         headers: {
    //             'Content-Type': 'application/x-www-form-urlencoded',
    //             "Authorization": "Bearer " + localStorage.getItem("access_token")
    //         },
    //         withCredentials: true
    //     }).then((response) => {
    //         this.comSexList = response.data;
    //     })
    // },
  }
}
</script>

<style scoped>
#box {
  background-color: #f2f2f2;
  width: 100%;
  height: 100%;
}

.el-select {
  display: inline-block;
  width: 100%;
}
</style>
